package com.keyue.config;

import com.keyue.common.utils.SecurityUtils;
import com.keyue.domain.RoleEnum;
import com.keyue.domain.vo.UserVO;
import com.keyue.domain.vo.admin.AdminResultVO;
import com.keyue.service.admin.AdminUserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 数据权限配置
 *
 * @date 2019-4-1
 */
@Component
public class DataScope {

    @Resource
    private AdminUserService userService;

    /**
     * @return
     */
    public Long getLoginUserId() {
        UserVO user = userService.findByUserName(SecurityUtils.getUsername());
        return user.getId();
    }

    /**
     * @return
     */
    public AdminResultVO isAdmin() {
        return userService.isAdmin(SecurityUtils.getUsername()).getData();
    }

    /**
     *
     * @return
     */
    public RoleEnum getRole() {
        return userService.getRoleBy(SecurityUtils.getUsername()).getData();
    }

    /**
     * @return
     */
    public String getLoginUserName() {
        return SecurityUtils.getUsername();
    }

    /**
     * @return
     */
    public UserVO getUser() {
        return userService.findByUserName(SecurityUtils.getUsername());
    }
}
